package view;

import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.ComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.event.ListDataListener;

/**
 * The Class AddNewLayersGUI.
 * @author Tomer
 */
public class AddNewLayersGUI extends AbstractGUI {
	
	/** The Link to file field. */
	private JTextField LinkToFileField = null;
	
	/** The lbl layer type. */
	private JLabel lblLayerType = null;
	
	/** The lbl link to file. */
	private JLabel lblLinkToFile = null;
	
	/** The combo box. */
	private JComboBox comboBox = null;
	
	/** The scroll pane. */
	private JScrollPane scrollPane = null;
	
	/** The btn add layer. */
	private JButton btnAddLayer = null;
	
	/**
	 * Instantiates a new adds the new layers gui.
	 */
	public AddNewLayersGUI() {
		getContentPane().setLayout(null);
		getContentPane().add(getLblLayerType());
		getContentPane().add(getLblLinkToFile());
		getContentPane().add(getComboBox());
		getScrollPane().setViewportView(getLinkToFileField());
		getContentPane().add(getScrollPane());
		getContentPane().add(getBtnAddLayer());
		getContentPane().add(getBackButton());
		
		this.setTitle("Add New Layer");
		this.setVisible(true);
		this.setBounds(200, 200, 412, 237);
		this.setResizable(false);
	}
	
	
	/**
	 * Gets the link to file field.
	 *
	 * @return the link to file field
	 */
	private JTextField getLinkToFileField(){
		if(LinkToFileField == null){
			LinkToFileField = new JTextField();
			LinkToFileField.setColumns(10);
		}
		return LinkToFileField;
	}
	
	/**
	 * Gets the lbl layer type.
	 *
	 * @return the lbl layer type
	 */
	private JLabel getLblLayerType(){
		if(lblLayerType == null){
			lblLayerType = new JLabel("Layer Type:");
			lblLayerType.setBounds(10, 45, 99, 14);
		}
		return lblLayerType;
	}
	
	/**
	 * Gets the lbl link to file.
	 *
	 * @return the lbl link to file
	 */
	private JLabel getLblLinkToFile(){
		if(lblLinkToFile == null){
			lblLinkToFile = new JLabel("Link To File:");
			lblLinkToFile.setBounds(10, 97, 88, 14);
		}
		return lblLinkToFile;
	}
	
	/**
	 * Gets the combo box.
	 *
	 * @return the combo box
	 */
	private JComboBox getComboBox(){
		if(comboBox == null)
		{
			comboBox = new JComboBox();
			comboBox.setBounds(113, 42, 231, 25);
		}
		return comboBox;
	}
	
	/**
	 * Gets the scroll pane.
	 *
	 * @return the scroll pane
	 */
	private JScrollPane getScrollPane(){
		if(scrollPane == null){
			scrollPane = new JScrollPane();
			scrollPane.setBounds(113, 95, 231, 28);
		}
		return scrollPane;
	}
	
	/**
	 * Gets the back button.
	 *
	 * @return the back button
	 */
	private JButton getBackButton(){
		if(backButton == null){
			backButton = new JButton("Back");
			backButton.setBounds(124, 176, 89, 23);
		}
		return backButton;
	}
	
	/**
	 * Gets the btn add layer.
	 *
	 * @return the btn add layer
	 */
	private JButton getBtnAddLayer(){
		if(btnAddLayer == null){
			btnAddLayer = new JButton("Add Layer");
			btnAddLayer.setBounds(10, 154, 105, 28);
		}
		return btnAddLayer;
	}
	
	/**
	 * Adds the add layer action listener.
	 *
	 * @param listener the listener
	 */
	public void addAddLayerActionListener(ActionListener listener){
		getBtnAddLayer().addActionListener(listener);
	}

	/**
	 * Sets the layer list.
	 *
	 * @param layerNames the new layer list
	 */
	public void setLayerList(String[] layerNames)
	{
		getContentPane().remove(comboBox);
		comboBox = new JComboBox<String>(layerNames);
		comboBox.setBounds(113, 42, 231, 25);
		getContentPane().add(comboBox);
		validate();
		repaint();
	}

	/**
	 * Gets the selected item.
	 *
	 * @return the selected item
	 * 
	 */
	public Object getSelectedItem() 
	{
		return comboBox.getSelectedItem();
	}
	
	/**
	 * Gets the link tofile text field.
	 *
	 * @return the link tofile text field
	 */
	public String getLinkTofileTextField()
	{
		return getLinkToFileField().getText();
	}
	
}
